package cn.wolfcode.service.impl;

import cn.wolfcode.domain.ActivityItem;
import cn.wolfcode.mapper.ActivityItemMapper;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.IActivityItemService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ActivityItemServiceImpl implements IActivityItemService {

    @Autowired
    private ActivityItemMapper activityItemMapper;


    @Override
    public void save(ActivityItem activityItem) {
        activityItemMapper.insert(activityItem);
    }

    @Override
    public void delete(Long id) {
        activityItemMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void update(ActivityItem activityItem) {
        activityItemMapper.updateByPrimaryKey(activityItem);
    }

    @Override
    public ActivityItem get(Long id) {
        return activityItemMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<ActivityItem> listAll() {
        return activityItemMapper.selectAll();
    }

    @Override
    public PageInfo<ActivityItem> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize()); //对下一句sql进行自动分页
        List<ActivityItem> activityItems = activityItemMapper.selectForList(qo); //里面不需要自己写limit
        return new PageInfo<ActivityItem>(activityItems);
    }

    @Override
    public int updateNum(Long id) {
        return activityItemMapper.updateNum(id);
    }

    @Override
    public List<ActivityItem> selectByAId(Long id) {
        return activityItemMapper.selectByAId(id);
    }


}
